package com.m3958.firstgwt.server.dao;


import com.m3958.firstgwt.client.types.AsyncTaskField;
import com.m3958.firstgwt.server.model.AsyncTask;
import com.m3958.firstgwt.server.model.AsyncTask.TaskCat;
import com.m3958.firstgwt.server.model.AsyncTask.TaskStatus;
import com.m3958.firstgwt.shared.type.CommonField;

public class AsyncTaskChangeStrategy extends BaseModelChangeStrategy implements ModelChangeStrategy<AsyncTask> {

	@Override
	public boolean extraPersistTask(AsyncTask model){//初始状态下以appdomian结尾的必须是通过审核的
		if(getReqPs().getStringValue(CommonField.NAME.getEname(), "").isEmpty()){
			TaskCat tc = (TaskCat) getReqPs().getEnumValue(TaskCat.class, AsyncTaskField.CATAGORY.getEname()); 
			switch (tc) {
			case CLONE_PAGE:
				model.setName("克隆頁面");
				break;
			case BIND_USER:
				model.setName("绑定帐号");
				break;
			default:
				break;
			}
		}
		model.setStatus(TaskStatus.UNTOUCHED.toString());
		model.setNotified(false);
		return true;
	}

	@Override
	public boolean extraRemoveTask(AsyncTask model) {
		return true;
	}

	@Override
	public boolean extraUpdateTask(AsyncTask model,AsyncTask newModel){
		return true;
	}

	@Override
	public boolean afterPersist(AsyncTask model) {
		return false;
	}
}
